const db = require('./db-util')

let sql_exists = "SELECT  u.user_id,u.username,r.* FROM user u  \n" +
    "inner join role r\n" +
    "on u.role_id = r.role_id\n" +
    " where u.username=? and u.password=?";

/**
 *  crud
 *  存在性-exists
 * */
function exists(user,callback) {
    db.query(sql_exists,[user.username,user.password],(err,rows)=>{
       // console.log(rows.length);
       // console.log(rows);
        const user = {
            userId : rows[0].user_id,
            username:rows[0].username,
            role:{
                roleId:rows[0].role_id,
                roleName:rows[0].role_name,
                remark:rows[0].remark
            }
        }
        callback(user);
    })
}

module.exports={
    exists
}
